package com.lcc.springconfig;

import com.lcc.springconfig.component.BeanLifeComponent;
import com.lcc.springconfig.model.User;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.AbstractApplicationContext;

@SpringBootApplication
public class SpringConfigApplication {
    public static void main(String[] args) {
        ApplicationContext context = SpringApplication.run(SpringConfigApplication.class, args);
//        User user = context.getBean(User.class);
////        user.setName("lisi");
//        System.out.println(user);
//        System.out.println("当前对象的内存地址为：" + System.identityHashCode(user));
//
//
//        User user2 = (User) context.getBean("user");
//        System.out.println(user2);
//        System.out.println("当前对象的内存地址为：" + System.identityHashCode(user2));
        BeanLifeComponent lifeComponent = context.getBean(BeanLifeComponent.class);
        lifeComponent.use();
        ((AbstractApplicationContext)context).destroy();//这样可以在不使用销毁方法的时候销毁Bean，但是是不建议使用的
    }

}
